package com.ke.video_clip.lib.widget;

import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.ke.video_clip.lib.R;

import java.util.ArrayList;
import java.util.List;


public class VideoTrimmerAdapter extends RecyclerView.Adapter<VideoTrimmerAdapter.TrimmerViewHolder> {
    private final List<Bitmap> mBitmaps = new ArrayList<>();


    @NonNull
    @Override
    public TrimmerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        return new TrimmerViewHolder(layoutInflater.inflate(R.layout.video_clip_lib_item_video_thumb, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull TrimmerViewHolder holder, int position) {
        (holder).thumbImageView.setImageBitmap(mBitmaps.get(position));
    }

    @Override
    public int getItemCount() {
        return mBitmaps.size();
    }

    public void addBitmaps(Bitmap bitmap) {
        mBitmaps.add(bitmap);
        notifyDataSetChanged();
    }

    final static class TrimmerViewHolder extends RecyclerView.ViewHolder {
        ImageView thumbImageView;

        TrimmerViewHolder(View itemView) {
            super(itemView);
            thumbImageView = (ImageView) itemView;
//              itemView.findViewById(R.id.thumb);
//      LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) thumbImageView.getLayoutParams();
//      layoutParams.width = VideoTrimmerUtil.VIDEO_FRAMES_WIDTH / VideoTrimmerUtil.MAX_COUNT_RANGE;
//      thumbImageView.setLayoutParams(layoutParams);
        }
    }
}
